package com.zzyl.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzyl.nursing.domain.DeviceData;
import com.zzyl.nursing.mapper.DeviceDataMapper;
import com.zzyl.nursing.mapper.DeviceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component("DeviceDataHistoryTask")
public class DeviceDataHistoryTask {

    @Autowired
    private DeviceMapper deviceMapper;

//    @Scheduled(cron = "0/5 * * * * *")  // 每 5 秒执行一次
    @Transactional(rollbackFor = Exception.class)
    public void sid(Integer minute) {
        System.out.println("执行定时任务: " + System.currentTimeMillis());
        //查询热表
        Long id = deviceMapper.getLastId(minute);
        //新增冷裱
        deviceMapper.insertIntoHistory(id);
        //删除冷裱
        deviceMapper.deleteOldLeID(id);
    }
}
